class Solution:
    def isValid(self, s: str) -> bool:
        dic = {')': '(', '}': '{', ']': '['}
        length = len(s)
        if length % 2:
            return False
        st = ['']*(length//2 + 1)
        top = -1
        for i in s:
            if i == '(' or i == '[' or i == '{' and top <= length//2:
                top += 1
                st[top] = i
            else:
                if st[top] == dic[i]:
                    top -= 1
                else:
                    return False
        if top != -1:
            return False
        return True


print(Solution().isValid("{[]}"))
